package org.chen.common.flight.request;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;

@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
@Schema(description = "航班搜索请求参数")
public class FlightSearchRequest {

    @Schema(description = "出发地机场代码",
            example = "CTU",
            requiredMode = Schema.RequiredMode.REQUIRED)
    @NotBlank(message = "出发地不能为空")
    private String departure;

    @Schema(description = "目的地机场代码",
            example = "BKK",
            requiredMode = Schema.RequiredMode.REQUIRED)
    @NotBlank(message = "目的地不能为空")
    private String destination;

    @Schema(description = "行程类型",
            example = "roundtrip",
            allowableValues = {"oneway", "roundtrip"},
            requiredMode = Schema.RequiredMode.REQUIRED)
    @NotBlank(message = "行程类型不能为空")
    @Pattern(regexp = "^(oneway|roundtrip)$", message = "行程类型只能是 oneway 或 roundtrip")
    private String tripType;

    @Schema(description = "出发日期",
            example = "2024-12-25",
            pattern = "yyyy-MM-dd",
            requiredMode = Schema.RequiredMode.REQUIRED)
    @NotBlank(message = "出发日期不能为空")
    @Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2}$", message = "日期格式必须为 yyyy-MM-dd")
    private String departDate;

    @Schema(description = "返程日期(往返行程时必填)",
            example = "2024-12-30",
            pattern = "yyyy-MM-dd",
            requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    @Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2}$", message = "日期格式必须为 yyyy-MM-dd")
    private String returnDate;

    @Schema(description = "准确时间过滤",
            example = "2024-12-30 12:00:00",
            pattern = "yyyy-MM-dd HH:mm:ss", // 使用大写 HH，表示24小时制
            requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    @Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$", message = "日期格式必须为 yyyy-MM-dd HH:mm:ss")
    private String orderDate;

    @Schema(description = "是否直飞",
            example = "true",
            allowableValues = {"true", "false"},
            requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    @Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$", message = "日期格式必须为 yyyy-MM-dd HH:mm:ss")
    private Boolean directFlight = true;

    @Schema(description = "成人数量",
            example = "1",
            minimum = "1",
            maximum = "9",
            defaultValue = "1")
    @Min(value = 1, message = "成人数量最少为1")
    @Max(value = 9, message = "成人数量最多为9")
    private int adults = 1;

    @Schema(description = "儿童数量(2-11岁)",
            example = "1",
            minimum = "0",
            maximum = "8",
            defaultValue = "0")
    @Min(value = 0, message = "儿童数量不能为负数")
    @Max(value = 8, message = "儿童数量最多为8")
    private int children = 0;

    @Schema(description = "婴儿数量(0-2岁)",
            example = "1",
            minimum = "0",
            maximum = "8",
            defaultValue = "0")
    @Min(value = 0, message = "婴儿数量不能为负数")
    @Max(value = 8, message = "婴儿数量最多为8")
    private int infants = 0;

    @Schema(description = "航班的语言代码",
            example = "zh",
            defaultValue = "zh",
            requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    private String lang = "zh";

    @Override
    public String toString() {
        return "FlightSearchRequest{" +
                "departure='" + departure + '\'' +
                ", destination='" + destination + '\'' +
                ", tripType='" + tripType + '\'' +
                ", departDate='" + departDate + '\'' +
                ", returnDate='" + returnDate + '\'' +
                ", adults=" + adults +
                ", children=" + children +
                ", infants=" + infants +
                '}';
    }
}